//
//  CZAccountTool.m
//  CZOC微博01
//
//  Created by 1 on 15/12/2.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "CZAccountTool.h"
#import "CZAccount.h"
@implementation CZAccountTool


+ (NSString *)getStrPath
{
    NSString *str=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  return  [str stringByAppendingPathComponent:@"account.data"];

}
+ (CZAccount *)account
{
    
    
    
CZAccount *account=[NSKeyedUnarchiver unarchiveObjectWithFile:[self getStrPath]];
    
    long long expires_in=[account.expires_in longLongValue];
    //获得过期的时间
    NSDate *date=[account.create_time dateByAddingTimeInterval:expires_in];
    NSDate *currentDate=[NSDate date];
    
    if([date compare:currentDate]==NSOrderedAscending)
     {
      //没有过期
         return nil;
    }
    
    return account;
}
+ (void)saveAccount:(CZAccount *)account
{
      //获得账号存储的时间
    account.create_time=[NSDate date];
    
    [NSKeyedArchiver archiveRootObject:account toFile:[self getStrPath]];
    
    
}

@end
